package com.order.server.controller;

import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.order.server.feign.StockFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    StockFeignClient stockFeignClient;

    @Autowired
    SentinelResourceAspect aspect;

    @RequestMapping("/createOrder")
    public String createOrder(@RequestParam("produceId") String productId) {
        String result = restTemplate.getForObject("http://stock-server/stock/reduce",String.class,productId);
        log.info("【调用结果】：{}",result);
        return "创建订单成功";
    }

    @RequestMapping("/createOrder2")
    public String createOrder2(@RequestParam("productId") String productId) {
        String result = stockFeignClient.reduce(productId);
        log.info("【调用结果】：{}",result);
        return "创建订单成功";
    }

    @RequestMapping("/test")
    public String test(){
        System.out.println(aspect);
        return "test";
    }

}
